package com.lvyq.myplayer.dao

import androidx.room.*
import com.lvyq.myplayer.model.current.CurrentPlayLstEntity
import com.lvyq.myplayer.parcelable.SongInfoData
import kotlinx.coroutines.flow.Flow

/**
 * 文件描述：CurrentPlayLstDao 播放列表
 * 作者：lvyq
 * 创建时间：2025-06-24
 * 修改时间：2025-06-24
 */

@Dao
interface CurrentPlayLstDao {


    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertCurrentPlayLst(data: CurrentPlayLstEntity)

    /**
     * 根据position 升序
     */
    @Query("SELECT * FROM play_current_lst  ORDER BY position ASC")
     fun getAllCurrentPlayLstFlow(): Flow<List<CurrentPlayLstEntity> >

    @Query("SELECT * FROM play_current_lst  ORDER BY position ASC")
    suspend fun getAllCurrentPlayLst(): List<CurrentPlayLstEntity>

    @Query("SELECT * FROM play_current_lst  WHERE position = :position")
    suspend fun getCurrentPlayLstByPosition(position:Int):CurrentPlayLstEntity

    @Query("DELETE FROM play_current_lst WHERE id = :id")
    suspend fun deleteById(id:Int)

    @Query("DELETE FROM play_current_lst WHERE id IN (:ids)")
    suspend fun deleteByIds(ids: List<Int>)

    @Query("DELETE FROM play_current_lst")
    suspend fun deleteAll()

    /**
     * 批量添加
     */
    @Insert
    suspend fun insertBatch(entities: List<CurrentPlayLstEntity>)

    @Query("DELETE FROM play_current_lst WHERE position = :position")
    suspend fun deleteByPosition(position: Int?)

    @Query("update  play_current_lst set position = position-1 where position> :position  ")
    suspend fun updPositionAfterDel(position: Int?)

    @Query("update  play_current_lst set position = position+1 where position> :position  ")
    suspend fun updPositionAfterAdd(position: Int?)
    @Insert
    fun insert(data: CurrentPlayLstEntity)
}
